package zust.study.java8feature.stream;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

public class Demo01_Base {
    public static void main(String[] args) {

        //filter
        List<String> strings = Arrays.asList("abc", "", "bc", "efg", "abcd","", "jkl");
        List<String> filtered = strings.stream().filter(string -> !string.isEmpty()).collect(Collectors.toList());
        filtered.forEach(System.out::println);

        //map
        List<Integer> nums = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
        List<Integer> numList = nums.stream().map(i -> i*i).collect(Collectors.toList());
        numList.forEach(n -> System.out.print(n + ", "));

        System.out.println();
        //sort
        Random random = new Random();random.setSeed(11);
        random.ints(0, 9).limit(25).sorted().forEach(n -> System.out.print(n + ", "));
    }
}
